package com.yanqu.road.server.gameplayer.module.activity.springdinner;

import com.alibaba.fastjson.JSONArray;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.springdinner.*;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.log.LogSpringDinnerGameOver;
import com.yanqu.road.entity.log.LogSpringDinnerMerge;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.bussiness.activity.SpringDinnerBusiness;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.logic.activity.condition.normal.UnionSameNicknameCountCondition;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.SpringDinnerProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.activity.springdinner.SpringDinnerMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class SpringDinnerModule extends GeneralModule {


    private SpringDinnerUserData userData;

    public SpringDinnerModule(GamePlayer player) {
        super(player);
    }

    public SpringDinnerUserData getUserData(){
        return userData;
    }


    public int redPacketEnter(int activityId,int no){
        SpringDinnerProto.CrossEnterRedPacketReqMsg.Builder msg = SpringDinnerProto.CrossEnterRedPacketReqMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setNo(no);
        msg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(UserMgr.parseUserBaseInfo(player.getUserInfo(), GameServer.getInstance().getServerId())));
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_ENTER, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        return 0;
    }

    public int openRedPacketTable(int activityId,String message){
        SpringDinnerProto.CrossOpenRedPacketTableReqMsg.Builder msg = SpringDinnerProto.CrossOpenRedPacketTableReqMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setIntegral(userData.getIntegral().longValue());
        msg.setMessage(message);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_OPEN, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        return 0;
    }

    public int robRedPacketTable(int activityId,int no){
        SpringDinnerProto.CrossRobRedPacketTableReqMsg.Builder msg = SpringDinnerProto.CrossRobRedPacketTableReqMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setNo(no);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_ROB, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        return 0;
    }

    public int tableRobUserList(int activityId,int no){
        SpringDinnerProto.CrossTableRobUserListReqMsg.Builder msg = SpringDinnerProto.CrossTableRobUserListReqMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setNo(no);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_ROB_USER_LIST, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        return 0;
    }

    public int robRedPacketRandom(int activityId){
        SpringDinnerProto.CrossRobRedPacketRandomReqMsg.Builder msg = SpringDinnerProto.CrossRobRedPacketRandomReqMsg.newBuilder();
        msg.setActivityId(activityId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_ROB_RANDOM, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
        return 0;
    }

    //红包的留言变成了许愿池弹幕了
    public int robRedPacketMessage(int activityId,int no,String message){
        //校验发言
        /*SpringDinnerProto.CrossRobRedPacketMessageReqMsg.Builder msg = SpringDinnerProto.CrossRobRedPacketMessageReqMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setNo(no);
        msg.setMessage(message);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_ROB_MESSAGE, msg);
        GamePlayerMgr.sendChannelPacket(player.getUserId(), pbMsg);*/
        return 0;
    }


    public int checkCommon(int activityId,int type){
        if(SpringDinnerMgr.getShowTimeActivityId() == 0 || SpringDinnerMgr.getShowTimeActivityId() != activityId){
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        if(!SpringDinnerMgr.activityInTime()){
            return GameErrorCode.E_ACTIVITY_OVER_TIME;
        }
        if(type != eSpringDinnerGameType.Normal.getValue() && type != eSpringDinnerGameType.Quick.getValue() && type != eSpringDinnerGameType.Fast.getValue()){
            return GameErrorCode.E_SPRINGDINNER_GAME_TYPE_ERR;
        }
        return 0;
    }

    public int checkUpLock(int activityId,int type){
        if(userData.getActivityId() != activityId){
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        int openScore = SpringDinnerMgr.getPlayModeScoreLimit(type);
        int openVip = SpringDinnerMgr.getPlayModeVipLimit(type);
        int userVip = VipMgr.getVipLv(player.getUserInfo().getVipExp());
        if(userVip < openVip && userData.getIntegral().compareTo(BigInteger.valueOf(openScore)) < 0){
            return GameErrorCode.E_SPRINGDINNER_GAME_TYPE_LIMIT;
        }
        return 0;
    }


    private SpringDinnerProto.SpringDinnerFruitData.Builder parseBallPb(BallData ball){
        SpringDinnerProto.SpringDinnerFruitData.Builder ballMsg = SpringDinnerProto.SpringDinnerFruitData.newBuilder();
        ballMsg.setFruitId(ball.getNo());
        ballMsg.setLevel(ball.getBallId());
        ballMsg.addPosition(""+ball.getX());
        ballMsg.addPosition(""+ball.getY());
        return ballMsg;
    }

    public SpringDinnerProto.SpringDinnerIntoRespMsg.Builder enterGame(int type){
        SpringDinnerProto.SpringDinnerIntoRespMsg.Builder msg = SpringDinnerProto.SpringDinnerIntoRespMsg.newBuilder();
        msg.setRet(0);
        msg.setType(type);

        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo != null && activityInfo.getChildType() == 2 && userData.getGameStatusMap().getOrDefault(type, false)) {
            msg.setHasGameData(false);
            return msg;
        }
        Map<Integer,BallData> ballMap = userData.getBallMap().get(type);
        for(BallData ball : ballMap.values()){
            msg.addFruits(parseBallPb(ball));
        }
        BallData nextBall = userData.getNextBall(type);
        msg.setNextFruitId(nextBall.getNo());
        msg.setNextLevel(nextBall.getBallId());
        msg.setNextFruitStep(nextBall.getStep());
        msg.setNextNoId(userData.getBallCount(type) + 1);
        msg.setHasGameData(true);
        return msg;
    }

    public SpringDinnerProto.SpringDinnerNewGameRespMsg.Builder startGame(int type){
        SpringDinnerProto.SpringDinnerNewGameRespMsg.Builder msg = SpringDinnerProto.SpringDinnerNewGameRespMsg.newBuilder();

        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo.getChildType() != 2) {
            // 暂不支持
            msg.setRet(GameErrorCode.E_ERROR_PARAMETER);
            return msg;
        }

        // 扣除体力  (暂定写死1)
        int needCost = SpringDinnerMgr.getMeituanDinnerEnergyCost();
        if (userData.getHp() < needCost) {
            // 扣除道具
            if (!player.getModule(CurrencyModule.class).removeCurrency(new Property(SpringDinnerMgr.getRecoverItemId(), needCost), eLogMoneyType.SpringDinnerActivity, eLogMoneyType.SpringDinnerActivityStartGame)) {
                msg.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
                return msg;
            }
        } else {
            // 扣除体力
            userData.setHp(userData.getHp() - needCost);
        }

        // 开启新游戏
        newGame(type);

        msg.setRet(0);
        msg.setType(type);
        BallData nextBall = userData.getNextBall(type);
        Map<Integer,BallData> ballMap = userData.getBallMap().get(type);
        for(BallData ball : ballMap.values()){
            msg.addFruits(parseBallPb(ball));
        }
        msg.setNextFruitId(nextBall.getNo());
        msg.setNextLevel(nextBall.getBallId());
        msg.setNextFruitStep(nextBall.getStep());
        msg.setNextNoId(userData.getBallCount(type) + 1);
        return msg;
    }

    //球是不是跑到场地之外了，除了y轴以外，超过y轴已经结束了
    private boolean isBallOutOfField(Map<Integer,BallData> ballMap){
        double xLeft = 0D;
        double xRight = SpringDinnerMgr.getxLenth();
        double yTop = 0D;
        double yFloor = - SpringDinnerMgr.getyLenth();
        for(BallData ballData : ballMap.values()){
            SpringDinnerBallConfig configBall = SpringDinnerMgr.getBallConfigById(ballData.getBallId());
            double ballYFloor = ballData.getY();
            if(ballYFloor < yFloor){
                log.error(ballData.getNo() + "球跑到Y下面,坐标" + ballYFloor);
                return true;
            }
            double ballXLeft = ballData.getX();
            if(ballXLeft < xLeft){
                log.error(ballData.getNo() + "球跑到X左边,坐标" + ballXLeft);
                return true;
            }
            double ballXRight = ballData.getY();
            if(ballXRight > xRight){
                log.error(ballData.getNo() + "球跑到X右边,坐标" + ballXRight);
                return true;
            }
        }
        return false;
    }

    //合成过程只考虑圆心
    private boolean isInComBallOutOfField(Map<Integer, ClientBallData> inComBallMap,Map<Integer,BallData> ballMap){
        double xLeft = 0D;
        double xRight = SpringDinnerMgr.getxLenth();
        double yTop = 0D;
        double yFloor = - SpringDinnerMgr.getyLenth();
        for(ClientBallData clientBallData : inComBallMap.values()){
            SpringDinnerBallConfig configBall = SpringDinnerMgr.getBallConfigById(ballMap.get(clientBallData.getNo()).getBallId());
            double ballYFloor = clientBallData.getY();
            if(clientBallData.getY() < yFloor){
                log.error(clientBallData.getNo() + "球圆心跑到Y下面,坐标" + ballYFloor);
                return true;
            }
            double ballXLeft = clientBallData.getX();
            if(clientBallData.getX() < xLeft){
                log.error(clientBallData.getNo() + "球圆心跑到X左边,坐标" + ballXLeft);
                return true;
            }
            double ballXRight = clientBallData.getY();
            if(clientBallData.getY() > xRight){
                log.error(clientBallData.getNo() + "球圆心跑到X右边,坐标" + ballXRight);
                return true;
            }
        }
        return false;
    }

    //合成过程中的球圆心不能跑到其他球里面
    private boolean isInComBallOverlap(Map<Integer, ClientBallData> inComBallMap,Map<Integer,BallData> ballMap){
        List<Integer> noIdList = new ArrayList<>(inComBallMap.keySet());
        Collections.sort(noIdList);
        for(int i = 0;i < noIdList.size() ; i++){
            ClientBallData clientBallData = inComBallMap.get(noIdList.get(i));
            for(int j = i + 1;j < noIdList.size(); j++){
                ClientBallData cpClientBallData = inComBallMap.get(noIdList.get(j));
                SpringDinnerBallConfig configBall = SpringDinnerMgr.getBallConfigById(ballMap.get(cpClientBallData.getNo()).getBallId());
                double xCut = clientBallData.getX() - cpClientBallData.getX();
                double yCut = clientBallData.getY() - cpClientBallData.getY();
                double distance = Math.sqrt(Math.pow(xCut,2) + Math.pow(yCut,2));
                double r = Double.valueOf("" + configBall.getWidth()/2) * cpClientBallData.getScale();
                if(distance < r){
                    log.info( "合成过程球校验:{}球圆心跑到圆{}里面了,圆心距离{},对比圆半径{}",
                            clientBallData.getNo(),cpClientBallData.getNo(),distance,r);
                    return true;
                }
            }
        }
        return false;
    }

    private boolean isBallOverlap(Map<Integer,BallData> ballMap){
        List<Integer> noIdList = new ArrayList<>(ballMap.keySet());
        Collections.sort(noIdList);
        for(int i = 0;i < noIdList.size() ; i++){
            BallData ballData = ballMap.get(noIdList.get(i));
            for(int j = i + 1;j < noIdList.size(); j++){
                BallData cpBallData = ballMap.get(noIdList.get(j));
                SpringDinnerBallConfig configBall = SpringDinnerMgr.getBallConfigById(cpBallData.getBallId());
                double xCut = ballData.getX() - cpBallData.getX();
                double yCut = ballData.getY() - cpBallData.getY();
                double distance = Math.sqrt(Math.pow(xCut,2) + Math.pow(yCut,2));
                double r = Double.valueOf("" + configBall.getWidth()/2);
                if(distance < r){
                    log.info( "最终球校验:{}球圆心跑到圆{}里面了,圆心距离{},对比圆半径{}",
                            ballData.getNo(),cpBallData.getNo(),distance,r);
                    return true;
                }
            }
        }
        return false;
    }

    private boolean isBallNotFall(Map<Integer, BallData> clientBallMap,double x, double y){
        for(BallData clientBall : clientBallMap.values()){
            if(clientBall.getY() == y){
                return true;
            }
        }
        return false;
    }


    //校验客户端发上来的数据合不合法
    private String checkBall(int type,BallData nextBall,Map<Integer, BallData> oBallMap,Map<Integer, BallData> clientBallMap,Map<Integer, ComposeData> composeMap,double x ,double y ,int clearBallId){
        //是放球下来x坐标肯定大于0
        if(x > 0 && isBallNotFall(clientBallMap,x,y)){
            return "有球没有下落";
        }
        if(isBallOutOfField(clientBallMap)){
            return "最终的球圆心有跑到盘面外的";
        }
        if(isBallOverlap(clientBallMap)){
//            return "最终的球圆心有跑到其他圆里的";
        }
        for(BallData ballData : clientBallMap.values()){
            SpringDinnerBallConfig ballConfig = SpringDinnerMgr.getBallConfigById(ballData.getBallId());
            if(ballConfig == null){
                return "找不到" + ballData.getBallId() + "球的配置信息";
            }
            if(ballConfig.getType() != type){
                return "场次不对应,场是" + type + "球是" + ballConfig.getType();
            }
        }
        Map<Integer,BallData> stepAllBallMap = new ConcurrentHashMap<>(oBallMap);
        stepAllBallMap.put(nextBall.getNo(),nextBall);
        if(clearBallId != 0){
            if(!oBallMap.containsKey(clearBallId)){
                return "消除的球"+clearBallId+"不在上一次的球数据中,消除了不存在的球";
            }
            stepAllBallMap.remove(clearBallId);
        }

        //最大的id，来每一次合成，防止客户端自己合了个传个不对的很大的值
        int maxBallId = userData.getBallCount(type);
        for(int i = 0; i < composeMap.size() ; i++){
            ComposeData composeData = composeMap.get(i);
            BallData ballDataA = stepAllBallMap.get(composeData.getBallIdA());
            BallData ballDataB = stepAllBallMap.get(composeData.getBallIdB());
            if(ballDataA == null || ballDataB == null){
                return "合成的两个球不在上一次的球的集合里,合成球id:" + composeData.getBall().getNo();
            }
            SpringDinnerBallConfig ballAConfig = SpringDinnerMgr.getBallConfigById(ballDataA.getBallId());
            if(ballAConfig == null){
                return "找不到合成球" + ballDataA.getBallId() + "的球的配置信息";
            }
            if(ballAConfig.getType() != type){
                return "合成场次不对应,场是" + type + "合成球是" + ballAConfig.getType();
            }
            //不是同一个级别的球合成
            if(ballDataA.getBallId() != ballDataB.getBallId()){
                return "合成的两个球不是同一个等级,合成球id:" + composeData.getBall().getNo();
            }
            //合成的球不对
            int composeBallId = SpringDinnerMgr.getComposeBallConfig(ballDataA.getBallId());
            if(composeBallId != composeData.getBall().getBallId()){
                return "合成的下一个等级不对,合成球id:" + composeData.getBall().getNo();
            }
            if(maxBallId + 1 != composeData.getBall().getNo()){
                return "合成的下一个序号不对,合成球id:" + composeData.getBall().getNo();
            }
            if(isInComBallOutOfField(composeData.getInComMap(),stepAllBallMap)){
                return "合成过程有球圆心跑到盘面外的，合成球id" + composeData.getBall().getNo();
            }
            if(isInComBallOverlap(composeData.getInComMap(),stepAllBallMap)){
                log.info("合成过程有球圆心跑到其它球，合成球id" + composeData.getBall().getNo() + "因为卡去掉了");
//                return "合成过程有球圆心跑到其它球，合成球id" + composeData.getBall().getNo();
            }
            maxBallId++;
            stepAllBallMap.remove(composeData.getBallIdA());
            stepAllBallMap.remove(composeData.getBallIdB());
            stepAllBallMap.put(composeData.getBall().getNo(),composeData.getBall());
        }
        return "";
    }

    //客户端合成的时候可能生成了新的球，把球生成的个数加一下
    private boolean setClientMaxBallId(int type,Map<Integer, BallData> clientBallMap){
        int maxBallId = 0;
        for(BallData ball : clientBallMap.values()){
            if(ball.getNo() > maxBallId){
                maxBallId = ball.getNo();
            }
        }
        Map<Integer,Integer> ballCountMap = userData.getBallCountMap();
        if(maxBallId != 0 && maxBallId > ballCountMap.get(type)){
            ballCountMap.put(type,maxBallId);
            userData.setBallCountMap(ballCountMap);
            return true;
        }
        return false;
    }

    private boolean isGameOver(int type, Map<Integer, BallData> clientBallMap) {
        Boolean gameStatus = userData.getGameStatusMap().getOrDefault(type, false);
        if (gameStatus) {
            return true;
        }
        for (BallData ball : clientBallMap.values()) {
            SpringDinnerBallConfig ballConfig = SpringDinnerMgr.getBallConfigById(ball.getBallId());
            BigDecimal value = new BigDecimal(ball.getY());
            value = value.add(new BigDecimal(ballConfig.getWidth()).divide(BigDecimal.valueOf(2), 4));
            if (value.compareTo(BigDecimal.valueOf(0)) >= 0) {
                return true;
            }
        }
        return false;
    }

    //生成下一个球
    private void makeNextBall(int type){
        Map<Integer,BallData> nextBallMap = userData.getNextBallMap();
        Map<Integer,Integer> ballCountMap = userData.getBallCountMap();
        Map<Integer,Integer> ballStepMap = userData.getStepMap();
        int count = ballCountMap.get(type);
        int step = ballStepMap.get(type);
        BallData nextBall = SpringDinnerMgr.getNextBall(type,step + 1,count + 1,userData.getBallMap().get(type));
        ballCountMap.put(type,count + 1);
        ballStepMap.put(type,step + 1);
        userData.setBallCountMap(ballCountMap);
        userData.setStepMap(ballStepMap);
        nextBallMap.put(type,nextBall);
        userData.setNextBallMap(nextBallMap);
    }

    //消除的时候可能生成了新的球，球id已经发送了变化
    private void setNextBallId(int type){
        Map<Integer,BallData> nextBallMap = userData.getNextBallMap();
        BallData nextBall = nextBallMap.get(type);
        Map<Integer,Integer> ballCountMap = userData.getBallCountMap();
        int count = ballCountMap.get(type);
        //消除的时候下一个球会被合成顶掉序号，所以当有合成的时候要重新设置一下下一个球的序号，但是也有可能没有合成
        //没有合成的时候生产球的总数和下一个球序号相同，有合成的时候下一个球的序号要加1
        if(count >= nextBall.getNo() && userData.getBallMap().get(type).containsKey(count)){
            nextBall.setNo(count + 1);
        }
        userData.setBallCountMap(ballCountMap);
        nextBallMap.put(type,nextBall);
        userData.setNextBallMap(nextBallMap);
    }

    public void useHpItem(long value){
        userData.setHp(userData.getHp() + (int)value);
        syncUserData();
    }

    private void recoveryHp(){
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        long nowTime = System.currentTimeMillis();
        if (activityInfo==null){
            return;
        }
        if (activityInfo.getChildType() == 1) {
            if (userData.getHp() >= SpringDinnerMgr.getMaxHp()) {
                userData.setHpTime(nowTime);
                return;
            }
            long passTime = nowTime - userData.getHpTime();
            long recoverTime = SpringDinnerMgr.getRecoverHpTime() * 1000;
            long recoverNum = passTime / recoverTime;
            long recoverHp = recoverNum * SpringDinnerMgr.getRecoverHp();
            if (recoverHp > 0) {
                if (recoverHp + userData.getHp() >= SpringDinnerMgr.getMaxHp()) {
                    userData.setHp(SpringDinnerMgr.getMaxHp());
                    userData.setHpTime(nowTime);
                } else {
                    userData.setHp(userData.getHp() + (int) recoverHp);
                    userData.setHpTime(userData.getHpTime() + recoverNum * recoverTime);
                }
            }
        } else {
            // 美团, 每日0点恢复
            long zeroTimeStamp = DateHelper.getTodayZeroTimeStamp();
            if (userData.getHpTime() < zeroTimeStamp) {
                userData.setHp(SpringDinnerMgr.getMaxHp());
                userData.setHpTime(zeroTimeStamp);
            }
        }
    }

    private void addMergeCount(int type,int ballId){
        Map<Integer, Map<Integer, Integer>> mergeMap = userData.getMergeMap();
        if(!mergeMap.containsKey(type)){
            mergeMap.put(type,new ConcurrentHashMap<>());
        }
        Map<Integer, Integer> ballMakeCountMap = mergeMap.get(type);
        if(!ballMakeCountMap.containsKey(ballId)){
            ballMakeCountMap.put(ballId,0);
        }
        ballMakeCountMap.put(ballId,ballMakeCountMap.get(ballId) + 1);
        userData.setMergeMap(mergeMap);
    }

    //第几步消除是减1步数，合成是当前步数
    public void addScore(int type,int step,Map<Integer, ComposeData> composeMap){
        if(composeMap.size() == 0)return;
        int modeMul = SpringDinnerMgr.getPlayModeScoreMul(type);
        int stepMul = SpringDinnerMgr.getStepScoreAdd(step);
        BigInteger rewardValue = BigInteger.ZERO;
        BigInteger addAllValue = userData.getIntegral();
        // 当前积分
        BigInteger currentValue = userData.getCurrentIntegralMap().getOrDefault(type, BigInteger.ZERO);
        for(ComposeData composeData : composeMap.values()){
            addMergeCount(type,composeData.getBall().getBallId());
            player.notifyListener(eGamePlayerEventType.SpringDinnerBall.getValue(),composeData.getBall().getBallId());
            SpringDinnerBallConfig ballConfig = SpringDinnerMgr.getBallConfigById(composeData.getBall().getBallId());
            BigInteger addValue = BigInteger.valueOf(ballConfig.getScore());
            addValue = addValue.multiply(BigInteger.valueOf(modeMul)).multiply(BigInteger.valueOf(stepMul)).divide(BigInteger.valueOf(1000));
            addAllValue = addAllValue.add(addValue);
            currentValue = currentValue.add(addValue);
            rewardValue = rewardValue.add(addValue);
        }
        player.getModule(CurrencyModule.class).addCurrency(SpringDinnerMgr.getScoreItemId() + "=" + rewardValue.longValue(),eLogMoneyType.SpringDinnerActivity,eLogMoneyType.SpringDinnerActivityGameCompose);
        userData.setIntegral(addAllValue);
        userData.getCurrentIntegralMap().put(type,currentValue);
        userData.setUpdateOption();
        addGameIntegral(type,rewardValue.longValue());
        player.notifyListener(eGamePlayerEventType.SpringDinnerScoreCrossRank.getValue(),userData.getIntegral());
        for (BigInteger currentIntegral : userData.getCurrentIntegralMap().values()) {
            player.notifyListener(eGamePlayerEventType.SpringDinnerMaxScoreCrossRank.getValue(), currentIntegral);
        }
    }

    public void addComposeLog(int type,Map<Integer, ComposeData> composeMap,int isDel,int isOver){
        if(composeMap.size() == 0)return;
        for(ComposeData composeData : composeMap.values()){
            SpringDinnerBallConfig ballConfig = SpringDinnerMgr.getBallConfigById(composeData.getBall().getBallId());
            BigInteger addValue = BigInteger.valueOf(ballConfig.getScore());
            LogSpringDinnerMerge log = new LogSpringDinnerMerge(
                    userData.getActivityId(),
                    userData.getUserId(),
                    type,
                    getGameNo(type),
                    userData.getStepMap().get(type),
                    isDel,
                    userData.getNextBall(type).getBallId(),
                    composeData.getBall().getBallId(),
                    composeData.getBall().getX() + "|" + composeData.getBall().getY(),
                    addValue.longValue(),
                    isOver,
                    System.currentTimeMillis()
            );
//            LogMgr.addLogSpringDinnerMerge(log);
            AutoLogMgr.add(log);
        }
    }


    public SpringDinnerProto.SpringDinnerComposeRespMsg.Builder composeBall(int type,Map<Integer, BallData> clientBallMap,Map<Integer, ComposeData> composeMap,double x,double y){
        SpringDinnerProto.SpringDinnerComposeRespMsg.Builder msg = SpringDinnerProto.SpringDinnerComposeRespMsg.newBuilder();
        msg.setRet(0);
        msg.setIsGameEnd(0);
        msg.setType(type);
        Map<Integer,Map<Integer,BallData>> typeBallMap = userData.getBallMap();
        Map<Integer,BallData> oBallMap = typeBallMap.get(type);
        String errStr = checkBall(type,userData.getNextBall(type),oBallMap,clientBallMap,composeMap,x,y,0);
        if(!"".equals(errStr)){
            msg.setErr(errStr);
            msg.setRet(GameErrorCode.E_SPRINGDINNER_GAME_BALL_ERR);
            return parseComposeBallMsg(msg,type);
        }
        // 体力恢复
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo == null) {
            msg.setErr(errStr);
            msg.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return parseComposeBallMsg(msg, type);
        }
        recoveryHp();
        // 消耗体力
        int countHp = SpringDinnerMgr.getCostHp(type);
        if(userData.getHp() - countHp < 0){
            msg.setRet(GameErrorCode.E_SPRINGDINNER_GAME_NO_HP);
            return parseComposeBallMsg(msg,type);
        }
        userData.setHp(userData.getHp() - countHp);
        addScore(type,userData.getNextBall(type).getStep(),composeMap);
        boolean isGameOver = isGameOver(type, clientBallMap);
        addComposeLog(type,composeMap,0,isGameOver?1:0);
        msg.setIsGameEnd(isGameOver?1:0);
        if (isGameOver) {
            //重新开始一局游戏
            Map<Integer, Integer> mergeBallCountMap = userData.getMergeMap().get(type);
            for (Integer ballId : mergeBallCountMap.keySet()) {
                SpringDinnerProto.ComposeCountTempMsg.Builder msgTemp = SpringDinnerProto.ComposeCountTempMsg.newBuilder();
                msgTemp.setFruitId(ballId);
                msgTemp.setCount(mergeBallCountMap.get(ballId));
                msg.addComposeCount(msgTemp);
            }
            if (activityInfo.getChildType() == 2) {
                // 美团的游戏结束了，标记一
                userData.getGameStatusMap().put(type, true);
                userData.getCurrentIntegralMap().put(type, BigInteger.ZERO);
            } else {
                newGame(type);
            }
        } else {
            typeBallMap.put(type, clientBallMap);
            userData.setBallMap(typeBallMap);
            setClientMaxBallId(type, clientBallMap);
            makeNextBall(type);
        }
        parseComposeBallMsg(msg,type);
        syncUserData();
        return msg;
    }

    private List<Integer> getLast3BallCountList(int type){
        List<Integer> countList = new ArrayList<>();
        Map<Integer, Integer> mergeBallCountMap = userData.getMergeMap().get(type);
        List<Integer> last3OneList = SpringDinnerMgr.getLast3BallId(type);
        for(Integer ballId : last3OneList){
            countList.add(mergeBallCountMap.getOrDefault(ballId,0));
        }
        return countList;
    }

    private SpringDinnerProto.SpringDinnerComposeRespMsg.Builder parseComposeBallMsg(SpringDinnerProto.SpringDinnerComposeRespMsg.Builder msg ,int type){
        Map<Integer,Map<Integer,BallData>> typeBallMap = userData.getBallMap();
        for(BallData ball : typeBallMap.get(type).values()){
            msg.addFruits(parseBallPb(ball));
        }
        BallData nextBall = userData.getNextBall(type);
        msg.setNextFruitId(nextBall.getNo());
        msg.setNextLevel(nextBall.getBallId());
        msg.setNextFruitStep(nextBall.getStep());
        msg.setNextNoId(userData.getBallCount(type) + 1);
        return msg;
    }

    private SpringDinnerProto.SpringDinnerClearRespMsg.Builder parseClearBallMsg(SpringDinnerProto.SpringDinnerClearRespMsg.Builder msg ,int type){
        Map<Integer,Map<Integer,BallData>> typeBallMap = userData.getBallMap();
        for(BallData ball : typeBallMap.get(type).values()){
            msg.addFruits(parseBallPb(ball));
        }
        BallData nextBall = userData.getNextBall(type);
        msg.setNextFruitId(nextBall.getNo());
        msg.setNextLevel(nextBall.getBallId());
        msg.setNextFruitStep(nextBall.getStep());
        msg.setNextNoId(userData.getBallCount(type) + 1);
        return msg;
    }

    private void newGame(int type){
        LogSpringDinnerGameOver log = new LogSpringDinnerGameOver(
                userData.getActivityId(),
                userData.getUserId(),
                type,
                getGameNo(type),
                userData.getHp(),
                userData.getStepMap().get(type),
                getGameIntegral(type),
                getClearTimes(type),
                JSONArray.toJSONString(userData.getMergeMap().get(type)),
                System.currentTimeMillis()
                );
//        LogMgr.addLogSpringDinnerGameOver(log);
        AutoLogMgr.add(log);

        nextGameNo(type);
        userData.getBallMap().put(type,new ConcurrentHashMap<>());
        userData.getBallCountMap().put(type,1);
        userData.getStepMap().put(type,1);
        userData.getNextBallMap().put(type,SpringDinnerMgr.getNextBall(type,1,1, userData.getBallMap().get(type)));
        userData.getMergeMap().put(type,new ConcurrentHashMap<>());
        userData.getClearMap().put(type,0);
        userData.getIntegralMap().put(type,0L);
        userData.getCurrentIntegralMap().put(type, BigInteger.ONE);
        // 游戏结束标识改回去
        userData.getGameStatusMap().put(type, false);
        userData.setUpdateOption();
    }

    public SpringDinnerProto.SpringDinnerClearRespMsg.Builder clearBall(int type,int clearBallId,Map<Integer, BallData> clientBallMap,Map<Integer, ComposeData> composeMap){
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        SpringDinnerProto.SpringDinnerClearRespMsg.Builder msg = SpringDinnerProto.SpringDinnerClearRespMsg.newBuilder();
        msg.setRet(0);
        msg.setType(type);
        Property consume = PropertyHelper.parseStringToProperty(SpringDinnerMgr.getGameClearItemId() + "=1");
        if(!player.getModule(CurrencyModule.class).currencyIsEnough(consume)){
            msg.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return parseClearBallMsg(msg,type);
        }
        player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.SpringDinnerActivity,eLogMoneyType.SpringDinnerActivityGameClear);
        Map<Integer,Map<Integer,BallData>> typeBallMap = userData.getBallMap();
        Map<Integer,BallData> oBallMap = typeBallMap.get(type);
        String errStr = checkBall(type,userData.getNextBall(type),oBallMap,clientBallMap,composeMap,0,0,clearBallId);
        if(!"".equals(errStr)){
            msg.setErr(errStr);
            msg.setRet(GameErrorCode.E_SPRINGDINNER_GAME_BALL_ERR);
            return parseClearBallMsg(msg,type);
        }
        addScore(type,userData.getNextBall(type).getStep(),composeMap);
        boolean isGameOver = isGameOver(type, clientBallMap);
        addComposeLog(type,composeMap,1,isGameOver?1:0);
        msg.setIsGameEnd(isGameOver?1:0);
        if(isGameOver){
            //重新开始一局游戏
            Map<Integer, Integer> mergeBallCountMap = userData.getMergeMap().get(type);
            for(Integer ballId : mergeBallCountMap.keySet()){
                SpringDinnerProto.ComposeCountTempMsg.Builder msgTemp = SpringDinnerProto.ComposeCountTempMsg.newBuilder();
                msgTemp.setFruitId(ballId);
                msgTemp.setCount(mergeBallCountMap.get(ballId));
                msg.addComposeCount(msgTemp);
            }
            if (activityInfo.getChildType() == 2) {
                // 美团的游戏结束了，标记一下
                userData.getGameStatusMap().put(type, true);
                userData.getCurrentIntegralMap().put(type, BigInteger.ZERO);
            } else {
                newGame(type);
            }
        }else{
            typeBallMap.put(type,clientBallMap);
            userData.setBallMap(typeBallMap);
            setClientMaxBallId(type,clientBallMap);
            //下一个球还是不变
//            setNextBallId(type);
        }
        parseClearBallMsg(msg,type);
        addClearTime(type);

        userData.setUpdateOption();
        syncUserData();
        return msg;
    }

    @Override
    public boolean loadData() {
        if(SystemOpenMgr.systemOpen(player, eSystemId.SpringDinner.getValue())){
            ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
            if(activityInfo != null && SpringDinnerMgr.activityInShowTime()){
                userData = SpringDinnerBusiness.getUserData(getUserId(),activityInfo.getActivityId());
                if(userData == null){
                    initUserData(activityInfo.getActivityId());
                }
            }
        }
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        if(userData != null){
            if(userData.isInsertOption()){
                SpringDinnerBusiness.addUserData(userData);
            }else if(userData.isUpdateOption()){
                SpringDinnerBusiness.updateUserData(userData);
            }
        }
        return true;
    }

    @Override
    public void afterLogin() {
        if(SystemOpenMgr.systemOpen(player, eSystemId.SpringDinner.getValue())){
            ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
            if(activityInfo != null && SpringDinnerMgr.activityInShowTime()){
                syncConfigData();
                syncUserData();
                // 美团的要检测下代金券
                if (activityInfo.getChildType() == 2) {
                    noticeMeiTuan();
                }
            }
        }
    }

    public void syncConfigData(){
        SpringDinnerProto.SpringDinnerConfigDataSyncMsg.Builder syncConfigDataMsg = SpringDinnerProto.SpringDinnerConfigDataSyncMsg.newBuilder();
        syncConfigDataMsg.setActivityId(SpringDinnerMgr.getShowTimeActivityId());
        syncConfigDataMsg.setConfigData(SpringDinnerMgr.getConfigDataTempBuilder(player.getLanguage()));
        player.sendPacket(Protocol.U_SPRINGDINNER_CONFIG_SYNC, syncConfigDataMsg);
    }

    public void syncUserData(){
        SpringDinnerProto.SpringDinnerUserDataSyncMsg.Builder syncUserDataMsg = SpringDinnerProto.SpringDinnerUserDataSyncMsg.newBuilder();
        syncUserDataMsg.setActivityId(SpringDinnerMgr.getShowTimeActivityId());
        syncUserDataMsg.setHp(userData.getHp());
        syncUserDataMsg.setHpTime((int)(userData.getHpTime()/1000));
        syncUserDataMsg.setIntegral(userData.getIntegral().longValue());
        syncUserDataMsg.setShareCount(userData.getShareCount());
        for (Map.Entry<Integer, BigInteger> entry : userData.getCurrentIntegralMap().entrySet()) {
            SpringDinnerProto.SpringDinnerCurrentIntegralTemp.Builder temp = SpringDinnerProto.SpringDinnerCurrentIntegralTemp.newBuilder();
            temp.setType(entry.getKey());
            temp.setIntegral(entry.getValue().longValue());
            syncUserDataMsg.addCurrentIntegral(temp);
        }
        player.sendPacket(Protocol.U_SPRINGDINNER_DATA_SYNC, syncUserDataMsg);


        //跨服的自己的数据同步
        SpringDinnerProto.CrossSyncUserDataReqMsg.Builder msg = SpringDinnerProto.CrossSyncUserDataReqMsg.newBuilder();
        msg.setActivityId(SpringDinnerMgr.getShowTimeActivityId());
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C2_SPRINGDINNER_ACTIVITY_CROSS_DATA_SYNC, msg);
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
    }

    public int getGameNo(int type){
        Map<Integer,Integer> gameNoMap = userData.getGameNoMap();
        if(!gameNoMap.containsKey(type)){
            gameNoMap.put(type,1);
        }
        return gameNoMap.get(type);
    }

    public void nextGameNo(int type){
        Map<Integer,Integer> gameNoMap = userData.getGameNoMap();
        if(!gameNoMap.containsKey(type)){
            gameNoMap.put(type,1);
        }
        gameNoMap.put(type,gameNoMap.get(type) + 1);
        userData.setGameNoMap(gameNoMap);
    }

    public int getClearTimes(int type){
        Map<Integer,Integer> clearMap = userData.getClearMap();
        if(!clearMap.containsKey(type)){
            clearMap.put(type,0);
        }
        return clearMap.get(type);
    }

    public void addClearTime(int type){
        Map<Integer,Integer> clearMap = userData.getClearMap();
        if(!clearMap.containsKey(type)){
            clearMap.put(type,0);
        }
        clearMap.put(type,clearMap.get(type) + 1);
        userData.setClearMap(clearMap);
    }

    public long getGameIntegral(int type){
        Map<Integer,Long> integralMap = userData.getIntegralMap();
        if(!integralMap.containsKey(type)){
            integralMap.put(type,0L);
        }
        return integralMap.get(type);
    }

    public void addGameIntegral(int type,long value){
        Map<Integer,Long> integralMap = userData.getIntegralMap();
        if(!integralMap.containsKey(type)){
            integralMap.put(type,0L);
        }
        integralMap.put(type,integralMap.get(type) + value);
        userData.setIntegralMap(integralMap);
    }

    public void initUserData(int activityId){
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if(userData == null || userData.getActivityId() != activityId){
            SpringDinnerUserData tempUserData = new SpringDinnerUserData();
            tempUserData.setActivityId(SpringDinnerMgr.getShowTimeActivityId());
            tempUserData.setUserId(getUserId());
            tempUserData.setHp(SpringDinnerMgr.getMaxHp());
            tempUserData.setIntegral(BigInteger.ZERO);
            tempUserData.setHpTime(System.currentTimeMillis());
            tempUserData.setUpdateTime(System.currentTimeMillis());
            Map<Integer, Integer> ballCountMap = new ConcurrentHashMap<>();
            ballCountMap.put(eSpringDinnerGameType.Normal.getValue(),1);
            ballCountMap.put(eSpringDinnerGameType.Quick.getValue(),1);
            ballCountMap.put(eSpringDinnerGameType.Fast.getValue(),1);
            tempUserData.setBallCountMap(ballCountMap);
            Map<Integer, Integer> stepMap = new ConcurrentHashMap<>();
            stepMap.put(eSpringDinnerGameType.Normal.getValue(),1);
            stepMap.put(eSpringDinnerGameType.Quick.getValue(),1);
            stepMap.put(eSpringDinnerGameType.Fast.getValue(),1);
            tempUserData.setStepMap(stepMap);
            Map<Integer, Map<Integer, BallData>> ballMap = new ConcurrentHashMap<>();
            ballMap.put(eSpringDinnerGameType.Normal.getValue(),new ConcurrentHashMap<>());
            ballMap.put(eSpringDinnerGameType.Quick.getValue(),new ConcurrentHashMap<>());
            ballMap.put(eSpringDinnerGameType.Fast.getValue(),new ConcurrentHashMap<>());
            tempUserData.setBallMap(ballMap);


            Map<Integer, BallData> nexBallMap = new ConcurrentHashMap<>();
            nexBallMap.put(eSpringDinnerGameType.Normal.getValue(),SpringDinnerMgr.getNextBall(eSpringDinnerGameType.Normal.getValue(),1,1,
                        ballMap.get(eSpringDinnerGameType.Normal.getValue())));
            nexBallMap.put(eSpringDinnerGameType.Quick.getValue(),SpringDinnerMgr.getNextBall(eSpringDinnerGameType.Quick.getValue(),1,1,
                        ballMap.get(eSpringDinnerGameType.Quick.getValue())));
            nexBallMap.put(eSpringDinnerGameType.Fast.getValue(),SpringDinnerMgr.getNextBall(eSpringDinnerGameType.Fast.getValue(),1,1,
                        ballMap.get(eSpringDinnerGameType.Fast.getValue())));
            tempUserData.setNextBallMap(nexBallMap);

            Map<Integer, Map<Integer, Integer>> mergeMap = new ConcurrentHashMap<>();
            mergeMap.put(eSpringDinnerGameType.Normal.getValue(),new ConcurrentHashMap<>());
            mergeMap.put(eSpringDinnerGameType.Quick.getValue(),new ConcurrentHashMap<>());
            mergeMap.put(eSpringDinnerGameType.Fast.getValue(),new ConcurrentHashMap<>());
            tempUserData.setMergeMap(mergeMap);

            Map<Integer, Integer> gameNoMap = new ConcurrentHashMap<>();
            gameNoMap.put(eSpringDinnerGameType.Normal.getValue(),1);
            gameNoMap.put(eSpringDinnerGameType.Quick.getValue(),1);
            gameNoMap.put(eSpringDinnerGameType.Fast.getValue(),1);
            tempUserData.setGameNoMap(gameNoMap);

            Map<Integer, Integer> clearMap = new ConcurrentHashMap<>();
            clearMap.put(eSpringDinnerGameType.Normal.getValue(),0);
            clearMap.put(eSpringDinnerGameType.Quick.getValue(),0);
            clearMap.put(eSpringDinnerGameType.Fast.getValue(),0);
            tempUserData.setClearMap(clearMap);

            Map<Integer, Long> integralMap = new ConcurrentHashMap<>();
            integralMap.put(eSpringDinnerGameType.Normal.getValue(),0L);
            integralMap.put(eSpringDinnerGameType.Quick.getValue(),0L);
            integralMap.put(eSpringDinnerGameType.Fast.getValue(),0L);
            tempUserData.setIntegralMap(integralMap);

            tempUserData.setHasMeiTuanNotice(false);
            tempUserData.setShareCount(0);
            tempUserData.setShareResetTime(DateHelper.getTodayZeroTimeStamp());

            tempUserData.setInsertOption();
            userData = tempUserData;
        }
    }

    /**
     * 系统解锁
     */
    public void initSystem() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if(activityInfo != null && SpringDinnerMgr.activityInShowTime()){
            initUserData(activityInfo.getActivityId());
            syncConfigData();
            syncUserData();
        }
    }

    /**
     * 添加美团代金券
     */
    public void addMeiTuanDaiJinQuan() {

    }

    /**
     * 美团代金券提醒
     */
    public void noticeMeiTuan() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (!ActivityHelper.activityInShowTime(activityInfo)) {
            return;
        }
        if (activityInfo.getChildType() != 2) {
            return;
        }
        if (userData == null || userData.isHasMeiTuanNotice()) {
            return;
        }
        if (System.currentTimeMillis() < activityInfo.getBeginTime() * 1000 + SpringDinnerMgr.getMeituanDinnerOverdueMail() * 60 * 1000) {
            return;
        }
        // 代金券列表
        List<GoodsInfo> infos = GoodsMgr.getGoodsListByType(eGoodsType.MeiTuanQuan.getValue());
        boolean hasDaiJinQuan = false;
        for (GoodsInfo goodsInfo : infos) {
            UserBagItem userBagItem = player.getModule(BagModule.class).getUserBagItem(goodsInfo.getGoodsId());
            if (userBagItem == null) {
                continue;
            }
            if (userBagItem.getNum() > 0) {
                hasDaiJinQuan = true;
                break;
            }
        }
        if (!hasDaiJinQuan) {
            // 没有代金券不处理
            return;
        }
        // 标记提醒过了
        userData.setHasMeiTuanNotice(true);

        // 发提醒
        String mailTitle = MultipleLanguageMgr.getContent(MailManager.MEITUANDINNER_MAIL_TITLE_1, player.getLanguage());
        String mailContent = MultipleLanguageMgr.getContent(MailManager.MEITUANDINNER_MAIL_CONTENT_1, player.getLanguage());
        MailManager.sendMail(player.getUserId(), eMailType.SYSTEM.getValue(), "", mailContent, mailTitle);
    }

    /**
     * 每日0点
     */
    public void resetOneDay() {
        if (userData == null) {
            return;
        }
        recoveryHp();
        // 今日0点时间戳
        long zeroTimeStamp = DateHelper.getTodayZeroTimeStamp();
        if (zeroTimeStamp > userData.getShareResetTime()) {
            // 重置分享次数
            userData.setShareCount(0);
            userData.setShareResetTime(zeroTimeStamp);
            // 同步下用户数据
            syncUserData();
        }
    }

    // 分享
    public int share() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo == null) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        if (activityInfo.getChildType() != 2) {
            return GameErrorCode.E_SPRINGDINNER_ONLY_MEI_TUAN;
        }
        if (userData == null) {
            return GameErrorCode.E_SPRINGDINNER_USER_NOT_FOUND;
        }
        if (userData.getShareCount() >= SpringDinnerMgr.getShareMaxNum()) {
            return GameErrorCode.E_SPRINGDINNER_SHARE_LIMIT;
        }
        userData.setShareCount(userData.getShareCount() + 1);

        // 获得分享奖励
        String reward = SpringDinnerMgr.getShareEnergyNum();
        player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(reward), eLogMoneyType.SpringDinnerActivity, eLogMoneyType.SpringDinnerActivityShareGet);

        SpringDinnerProto.SpringDinnerShareRespMsg.Builder respMsg = SpringDinnerProto.SpringDinnerShareRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.setReward(reward);
        player.sendPacket(Protocol.U_SPRINGDINNER_SHARE, respMsg);

        // 同步下用户数据
        syncUserData();
        return 0;
    }
}
